package xyz.luckyli.springcloud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import xyz.luckyli.springcloud.pojo.Dept;

import java.util.List;


/**
 * ClassName:DeptConsumerController
 * Package:xyz.luckyli.springcloud.controller
 * Description:
 *
 * @Date:2020/9/29 15:06
 * @Author:857251389@qq.com
 */

@RestController
public class DeptConsumerController {

    //消费者不应该有service层，使用RestTemplate


    @Autowired
    private RestTemplate restTemplate;


    private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-DEPT";
    @RequestMapping("/consumer/dept/add")
    public Boolean add(Dept dept){
        return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Boolean.class);
    }

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept getById(@PathVariable("id") Long id){

        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id,Dept.class);

    }

    @RequestMapping("/consumer/dept/list")
    public List<Dept> list(){

        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list",List.class);
    }




}
